import Divider from "@/src/components/divider"
import { Axis } from "@/src/consts"
import GoodsCartModel from "@/src/lib/models/goods_cart_model"
import { View } from "@tarojs/components"
import Item from "./item"

import "./list.scss"

export interface ListPorps {
    title?: string,
    titleRightEl?: any
    footer?: any,

    models?: GoodsCartModel[],
}


const List = (props: ListPorps) => {


    let children = new Array()
    if (props.models) {
        for (const model of props.models) {
            children.push(<Item model={model} />)
            children.push(<Divider className="divider" color="#F2F2F2" />)
        }

        children.pop()
    }



    let footerEl
    if (props.footer) {
        footerEl = (
            <View style={{padding: "0 30rpx"}}>
                <Divider className="divider" axis={ Axis.horizontal } color="#F2F2F2" />
                { props.footer}
            </View>
        )
    }


    return (
        <View className="list">
            <View className="list-header">
                <View className="list-title">{ props.title }</View>
                { props.titleRightEl }
            </View>
            
            { children }
            { footerEl }
        </View>
    )
}

export default List